package com.lovo.middleman.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.middleman.bean.BuyBean;
import com.lovo.middleman.bean.SupplierBean;
import com.lovo.middleman.mapper.BuyMapper;
import com.lovo.middleman.mapper.SupplierMapper;
import com.lovo.middleman.service.IBuyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BuyServiceImpl extends ServiceImpl<BuyMapper, BuyBean> implements IBuyService {

    @Autowired
    BuyMapper buyMapper;

    @Autowired
    SupplierMapper supplierMapper;

    @Override
    public List<SupplierBean> queryAllSupplierBean() {
        QueryWrapper<SupplierBean> queryWrapper = new QueryWrapper<>();
        queryWrapper.gt("supplier_id", 0);
        return supplierMapper.selectList(queryWrapper);
    }



    @Override
    public Page<BuyBean> queryBuyBeanByItem(int curPage,
                                            int pageSize,
                                            String supplierName,
                                            String starTime,
                                            String endTime) {
        QueryWrapper<BuyBean> queryWrapper = new QueryWrapper<>();
        if (supplierName != null && !"".equals(supplierName)) {
            queryWrapper.like("supplier_name", supplierName);
        }
        if (starTime != null && !"".equals(starTime)) {
            queryWrapper.gt("buy_time", starTime);
        }
        if (endTime != null && !"".equals(endTime)) {
            queryWrapper.lt("buy_time", endTime);
        }
        return buyMapper.selectPage(new Page<>(curPage, pageSize), queryWrapper);

    }

    @Override
    public BuyBean queryBuyBeanById(int id) {
        return buyMapper.selectById(id);
    }
}
